const AV = require('../../libs/av-weapp-min.js');
//index.js

Page({
    data: {
        center: {
            longitude: 0,
            latitude: 0
        },
        map_height: "0px",
        markers: [],
        controls: []
    },
    regionchange(e) {
        console.log(e.type)
    },
    markertap(e) {
        let item = this.data.markers.find(x => x.id == e.markerId);
        wx.setStorageSync('selected_site', item);
        wx.navigateTo({
            url: `/pages/info/info`
        })
    },
    onLoad() {
        this.setData({
            markers: JSON.parse(wx.getStorageSync('results')).map(x => (Object.assign(
                x,
                {
                    iconPath: "/resources/others.png",
                    width: 50,
                    height: 50
                }, x.location
            )))
        });
        //获取用户当前位置
        wx.getLocation({
            type: 'gcj02',
            success: res => {
                this.setData({
                    'center.latitude': res.latitude,
                    'center.longitude': res.longitude
                })
            }
        });

        //设置控件位置
        wx.getSystemInfo({
            success: res => {
                this.setData({ 'controls[0].position.left': res.windowWidth - 60 });
                this.setData({ 'controls[0].position.top': res.windowHeight - 100 });
                this.setData({ 'map_height': res.windowHeight + 'px' });
            }
        });
    }
})

